--[[
	gSpeak
	Author: Adult
]]--

-- Net enumerators
VOICE_GETCHANNELS = "voice_getchannels"
VOICE_REMOVE      = "voice_remove"
VOICE_ADD         = "voice_add"
VOICE_BAN         = "voice_ban"
VOICE_KICK        = "voice_kick"
VOICE_REQJOIN     = "voice_reqjoin"
VOICE_LEAVE       = "voice_leave"
VOICE_MESSAGE     = "voice_message"
VOICE_DATA        = "voice_data" 
VOICE_REQDATA     = "voice_reqdata"

--------- Overall Helpers ------------
function isValidPlayer( ply )
	return IsValid( ply ) or ply:IsPlayer()
end

function findPlyBySteamID( steamid ) 
	local ply = nil
	for _,v in pairs( player.GetAll() ) do
		if v:SteamID() == steamid then
			ply = v
		end
	end

	return ply 
end

---------  Channel Helpers -----------
function channelExists( id )
	return voice.channels[id] ~= nil 
end

function channelAdmin( id )
	if not channelExists( id ) then
		return false
	end

	return voice.channels[id].admin 
end

function channelMembers( id )
	if not channelExists( id ) then
		return false
	end

	return voice.channels[id].members 
end

function channelBanned( id )
	if not channelExists( id ) then
		return false
	end

	return voice.channels[id].banned 
end

local plymeta = FindMetaTable( "Player" )

function plymeta:isBannedFromChannel( id )
	return table.HasValue( voice.channels[id].banned, self:SteamID() )
end

function plymeta:isInChannel( id )
	return table.HasValue( voice.channels[id].members, self:SteamID() )
end

function plymeta:isChannelAdmin( id )
	return table.HasValue( voice.channels[id].admin, self:SteamID() )
end

function plymeta:isGAdmin()
	return table.HasValue( voice.admins, self:SteamID() )
end

function plymeta:getGSpeakChannel()
	return self:GetNWString( "gspeak_channel" ) or nil 
end

function plymeta:setGSpeakChannel( id )
	if not SERVER then return false end
	return self:SetNWString( "gspeak_channel", id )
end